import React from "react";
import { Link, Routes, Route, useParams } from "react-router-dom";

const Home = () => {
  return <div>这是首页</div>;
};
const About = () => {
  return <div>这是关于页</div>;
};

// 6版本的所有路由组件，都是不带路由信息的
// withRouter没有了，想拿路由信息只能拿hooks了
const Detail = () => {
  const params = useParams();
  console.log(params.id);
  return <div>这是详情页</div>;
};

const App = () => {
  return (
    <>
      <h2>路由基础-v6</h2>
      <ul>
        <li>
          <Link to="/">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          <Link to="/detail/234">详情页</Link>
        </li>
        <li>
          <Link to="/detail/567">详情页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
        {/* 因为精准匹配，不能直接显示页面了，只能加上/:id */}
        <Route path="/detail/:id" element={<Detail />}></Route>
      </Routes>
    </>
  );
};

export default App;
